package cn.itcast.service.impl;

import cn.itcast.dao.CourierDao;
import cn.itcast.dao.StandardDao;
import cn.itcast.domain.Courier;
import cn.itcast.domain.Standard;
import cn.itcast.service.CourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CourierServiceImpl implements CourierService{
    @Autowired
    private CourierDao courierDao;
    @Autowired
    private StandardDao standardDao;

//    public List<Standard> findAll(){
//        List<Standard> list = standardDao.findAll();
//        return list;
//    }

    @Transactional
    @Override
    public void save(Courier courier) {
        courierDao.save(courier);
    }

    @Override
    public Page<Courier> pageQuery(int page, int rows) {
        PageRequest pageable = PageRequest.of(page - 1, rows);
        return courierDao.findAll(pageable);
    }

    @Transactional
    @Override
    public void delBatch(String[] idArray) {
        for (String idStr : idArray) {
            int id = Integer.parseInt(idStr);
            courierDao.updateDelTag(id);
        }
    }

    @Transactional
    @Override
    public void restore(String[] idArray) {
        for (String str : idArray) {
            int id = Integer.parseInt(str);
            courierDao.updateRestore(id);
        }
    }
}
